//
//  CourseCell.m
//  MetenEnglish
//
//  Created by rj-mayong on 14/11/28.
//  Copyright (c) 2014年 Shenzhen Securities Information Co., Ltd. All rights reserved.
//

#import "CourseCell.h"
#import "CourseModel.h"
#import "Tools.h"

@interface CourseCell()

@property (nonatomic, assign, readonly) NSInteger cellType;

@end

@implementation CourseCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier
                     cellType:(CELL_TYPE)cellType {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _cellType = cellType;
        [self initializationUI];
    }
    return self;
}

- (void)initializationUI {
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 180, 30)];
    _nameLabel.text = @"name";
    _nameLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.contentView addSubview:_nameLabel];

    _teacherLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 15, 105, 30)];
    _teacherLabel.text = @"teacher";
    _teacherLabel.font = CELL_SIZE;
    [self.contentView addSubview:_teacherLabel];

    _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 85, 200, 30)];
    _timeLabel.text = @"time";
    _timeLabel.font = CELL_SIZE;
    [self.contentView addSubview:_timeLabel];

    _statusButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _statusButton.frame = CGRectMake(220, 85, 85, 30);
    [_statusButton setTitle:@"status" forState:UIControlStateNormal];
    [_statusButton setTitleColor:OVERALL_COLOR forState:UIControlStateNormal];
    [_statusButton addTarget:self action:@selector(reserveCourse:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_statusButton];
    
    if (_cellType == CELL_COURSELIST) {
        _reservedNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 50, 70, 30)];
        _reservedNumLabel.text = @"reservedNum";
        _reservedNumLabel.font = CELL_SIZE;
        [self.contentView addSubview:_reservedNumLabel];
        
        _queuedNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 50, 70, 30)];
        _queuedNumLabel.text = @"queuedNum";
        _queuedNumLabel.font = CELL_SIZE;
        [self.contentView addSubview:_queuedNumLabel];
        
        _addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 50, 140, 30)];
        _addressLabel.text = @"address";
        _addressLabel.font = CELL_SIZE;
        [self.contentView addSubview:_addressLabel];
    }
    else if (_cellType == CELL_RESERVEDLIST) {
        _addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 50, 290, 30)];
        _addressLabel.text = @"address";
        _addressLabel.font = CELL_SIZE;
        [self.contentView addSubview:_addressLabel];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)reserveCourse:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(clickedCourseButton:)]) {
        [_delegate performSelector:@selector(clickedCourseButton:) withObject:_courseModel];
    }
}

- (void)setCellContent:(CourseModel *)course {
    _courseModel = course;
    
    _nameLabel.text = course.name;
    _teacherLabel.text = course.teacher;
    _reservedNumLabel.text = course.resevedNum;
    _queuedNumLabel.text = course.queuedNum;
    _addressLabel.text = course.address;
    _timeLabel.text = course.time;
    
    if (course.status == nil) {
        [_statusButton setTitle:@"我要退课" forState:UIControlStateNormal];
    }
    else {
        [_statusButton setTitle:course.status forState:UIControlStateNormal];
    }
}

@end
